<?php

namespace App\Http\Resources\Counter;

use App\Cost\CostType;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class TableTypeResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $perMinutePrice = round($this->defaultRule?->data->getPerMinutesPrice(), 2) ?? null;

        return [
            'id' => $this->id,
            'name' => $this->name,
            'start_num' => $this->start_num,
            'default_people_count' => $this->default_people_count,
            'type' => $this->type,
            'count' => $this->count,
            'tables' => TableListResource::collection($this->tables),
            'cost_rules' => $this->costRules,
            'default_rule' => $this->defaultRule,
            'per_minute_price' => $perMinutePrice,
        ];
    }
}
